package com.lehecai.core.task.type;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * Created by qatang on 14-3-26.
 */
public enum AsyncTaskType {
    ALL("全部"),
    TASK_PLAN_DRAW("开奖任务");

    private static Logger logger = LoggerFactory.getLogger(AsyncTaskType.class);

    private static final Map<Integer, AsyncTaskType> _MAP = new HashMap<Integer, AsyncTaskType>();
    private static List<AsyncTaskType> _LIST = new ArrayList<AsyncTaskType>();
    private static List<AsyncTaskType> _ALL_LIST = new ArrayList<AsyncTaskType>();
    static {
        for(AsyncTaskType asyncTaskType : AsyncTaskType.values()){
            _MAP.put(asyncTaskType.getValue(), asyncTaskType);
            _ALL_LIST.add(asyncTaskType);
            if (!asyncTaskType.equals(ALL)) {
                _LIST.add(asyncTaskType);
            }
        }

        synchronized (_LIST) {
            _LIST = Collections.unmodifiableList(_LIST);
        }
        synchronized (_LIST) {
            _ALL_LIST = Collections.unmodifiableList(_ALL_LIST);
        }
    }

    private String name;

    private AsyncTaskType(String name){
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public int getValue(){
        return this.ordinal();
    }

    public static AsyncTaskType get(int value){
        try{
            return _MAP.get(value);
        }catch(Exception e){
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static List<AsyncTaskType> list() {
        return _LIST;
    }

    public static List<AsyncTaskType> listAll() {
        return _ALL_LIST;
    }
}
